//初始化echarts实例
var chartDom = document.getElementById('c2');
var myChart = echarts.init(chartDom,'dark');
var option_cksj;
function randomData() {
  now = new Date(+now + oneDay);
  value = value + Math.random() * 21 - 10;
   return {
    name: now.toString(),
    value: [
      [[now.getFullYear(), now.getMonth()+1, now.getDate()].join('-'),[now.getHours(),now.getMinutes()].join(':')].join(' '),
      10
    ]
  };
}

let data = [];
let now = new Date(2020,11,21,23,40,0);
let oneDay = 60 * 1000;
let value = Math.random() * 1000;
for(let i =0;i<20;i++){
	data.push(randomData())
}

option_cksj = {
  title: {
	text: '出站数量实时统计'
  },
  tooltip: {
	trigger: 'axis',
	formatter: function (params) {

		params = params[0];

	  var date = new Date(params['name']);
	  return (
		date.getDate() +
		'日' +
		date.getHours() +
		'点' +
		date.getMinutes() +
		' 分: ' +
		params['value'][1]
	  );
	},
	axisPointer: {
	  animation: false
	}
  },
  xAxis: {
	type: 'time',
	splitLine: {
	  show: false
	},
	formatter: function (data) {

		var t_date = new Date(data[0]['name']);

		return [t_date.getMonth() , t_date.getDate()].join('/') + " "

			+ [t_date.getHours(), t_date.getMinutes()].join(':');

	}
  },
  yAxis: {
	type: 'value',
	boundaryGap: [0, '100%'],
	splitLine: {
	  show: false
	}
  },
  series: [
	{
	  name: 'Fake Data',
	  type: 'line',
	  showSymbol: false,
	  data: data
	}
  ]
};

setInterval(function () {

	for (var i = 0; i < 1; i++) {
		data.shift()
		data.push(ck[0])
		ck.shift()
		}


  myChart.setOption({
	series: [
	  {
		data: data
	  }
	]
  });
}, 1000);

option_cksj && myChart.setOption(option_cksj);
